package dayOfTheWeek;

public class Solution {
    public String dayOfTheWeek(int day, int month, int year) {
        String[] arr=new String[]{"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"};
        int dayIndex=dayOfYear(year,month,day);
        int firstDay=getFirstDay(year);
        System.out.println(firstDay+" "+dayIndex);
        return arr[(dayIndex%7-1+firstDay)%firstDay];
    }

    public static void main(String[] args) {
        System.out.println(199%7);
    }
    public int dayOfYear(int year,int month,int day) {
        int[] amount = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
        if (year % 400 == 0 || (year % 4 == 0 && year % 100 != 0)) {
            ++amount[1];
        }
        int ans = 0;
        for (int i = 0; i < month - 1; ++i) {
            ans += amount[i];
        }
        return ans + day;
    }

    private int getFirstDay(int year){
        int s=0;
//for循环,先计算输入年份距离公元1月1日有多少天
        for(int i=1; i<year; i++){
            if(i%4==0 && i%100!=0 || i%400==0){
                s=s+366;
            }else{
                s=s+365;
            }
        }
        int week = (s%7)+1;
        return week%7;
    }
}
